using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using System;
using System.Collections.Generic;
namespace MicroMsg.Scene
{
	public class NetSceneBatchGetContact : NetSceneBaseEx<GetContactRequest, GetContactResponse, GetContactRequest.Builder>
	{
		private const string TAG = "NetSceneBatchGetContact";
		public bool doScene(List<string> userNameList)
		{
			return new NetSceneBatchGetContact().doSceneEx(userNameList);
		}
		private bool doSceneEx(List<string> userNameList)
		{
			Log.smethod_4("NetSceneBatchGetContact", "doscene in");
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			using (List<string>.Enumerator enumerator = userNameList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					this.mBuilder.UserNameListList.Add(Util.toSKString(BContactMgr.toBottleContactUserName(current)));
				}
			}
			this.mBuilder.UserCount = (uint)this.mBuilder.UserNameListList.get_Count();
			this.mSessionPack.mCmdID = 71;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(GetContactRequest request, GetContactResponse response)
		{
			Log.smethod_1("NetSceneBatchGetContact", "onFailed in");
			EventCenter.postEvent(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR, RetConst.MM_ERR_CLIENT, null);
		}
		protected override void onSuccess(GetContactRequest request, GetContactResponse response)
		{
			Log.smethod_4("NetSceneBatchGetContact", "onSuccess in");
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneBatchGetContact", "send BatchGetContactRequest failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_ERR, ret, null);
				return;
			}
			List<object> list = new List<object>();
			using (IEnumerator<ModContact> enumerator = response.ContactListList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ModContact current = enumerator.get_Current();
					string @string = current.UserName.String;
					Log.smethod_4("NetSceneBatchGetContact", string.Concat(new object[]
					{
						"BatchGetContactRequest update contact, userName = ",
						@string,
						" contact.City=",
						current.City,
						" contact.Province = ",
						current.Province,
						" Sex=",
						current.Sex,
						" Signature=",
						current.Signature
					}));
					if (ContactHelper.isBottleContact(@string))
					{
						NetSceneNewSync.processModBottleContact(NetSceneBatchGetContact.ModContactToModBottleContact(current));
					}
					else
					{
						list.Add(current);
					}
				}
			}
			if (list.get_Count() > 0)
			{
				NetSceneNewSync.processModContactCmdList(list);
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_SUCCESS, list, null);
		}
		private static ModBottleContact ModContactToModBottleContact(ModContact contact)
		{
			ModBottleContact.Builder builder = ModBottleContact.CreateBuilder();
			builder.UserName = contact.UserName.String;
			builder.Type = contact.ContactType;
			builder.Sex = (uint)contact.Sex;
			builder.City = contact.City;
			builder.Province = contact.Province;
			builder.Signature = contact.Signature;
			builder.ImgFlag = contact.ImgFlag;
			builder.HDImgFlag = contact.HasWeiXinHdHeadImg;
			return builder.Build();
		}
	}
}
